package im.vinci.server.device.persistence;

import im.vinci.server.device.domain.CrashLog;
import im.vinci.server.device.domain.Device;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * Created by henryhome on 9/15/15.
 */
@Repository
public interface DeviceMapper {

    @Insert("insert into crash_log (imei, mac, crash_type, crash_count, app_name, app_version, log_sign, log) " +
            "values (#{imei}, #{mac}, #{crashType}, #{crashCount}, #{appName}, #{appVersion}, #{logSign}, #{log})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public Integer addCrashLog(CrashLog crashLog);

    @Insert("insert into device_headphone_info (sn, mac, imei,iot_device_id,iot_device_secret ) " +
            "values (#{sn}, #{mac}, #{imei}, #{iotDeviceId} ,#{iotDeviceSecret}) " +
            "ON DUPLICATE KEY UPDATE iot_device_id=#{iotDeviceId},iot_device_secret=#{iotDeviceSecret}")
    @Options(useGeneratedKeys = true, keyColumn = "id")
    public int addDevice(Device device);

    @Select("select * from device where imei = #{imei}")
    public Device getDeviceByImei(String imei);

    @Select("select * from device where imei = #{sn}")
    public Device getDeviceBySn(String sn);
}



